<?php

use Sharks\Core\AppContext;
use Sharks\Core\Http\Routing\RouteControl;
use Sharks\Core\Support\Base\DefValue;

/**
 * 生成route的URL
 * 参数：
 * 	action: 
 * 	query
 * 	hash
 * 	method
 * 	
 * @param  array $params  参数数组
 * @param  [type] &$smarty [description]
 */
function smarty_function_route($params, &$smarty) {
	if (isset($params['action']) && !empty($params['action'])) {
		
		$action = $params['action'];
		$query = DefValue::pick($params, 'query', array());
		$hash = DefValue::pick($params, 'hash', null);
		$method = DefValue::pick($params, 'method', null);

		// http 方法
		if (null != $method && ('get' != $method || 'GET' != $method)) {
			$query['_method'] = $method;
		}
		
		unset($params['route']);
		unset($params['query']);
		unset($params['hash']);
        unset($params['action']);

		echo RouteControl::url($action, $params, $query, $hash);
	}
}